package com.xiaoshuidi.cloud.module.bpm.enums.reserveticket;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.xiaoshuidi.cloud.framework.common.exception.ErrorCode;
import com.xiaoshuidi.cloud.framework.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 预约工单 - 进度枚举
 */
@Getter
@AllArgsConstructor
public enum ReserveProgressEnum {

    PENDING("待处理","0"),
    CALLED("已去电","1"),
    TAKEN_TO_SEE("已带看","2"),
    POSTPONE("推迟","3"),
    ABANDON("放弃","4"),
    INVALID("无效","5"),
    CONTRACTED("已签约","6");

    private String name;
    private String value;

    public static String getNameByValue(String value) {
        ReserveProgressEnum reserveProgressEnum = Arrays.stream(ReserveProgressEnum.values()).filter(p -> p.getValue().equals(value)).findFirst().orElse(null);
        if(ObjectUtil.isEmpty(reserveProgressEnum)){
            throw new ServiceException(new ErrorCode(100322, StrUtil.format("预约工单进度枚举value{}不存在",value)));
        }
        return reserveProgressEnum.getName();
    }
}
